#pragma once
#include "../ComPtrEx.h"
#include "../SevenZip/SevenZipArchiveItem.h"

struct CSevenZipFolder;

struct CPropertyStoreFactory : CComObjectRootEx<CComSingleThreadModel>,
	                           IPropertyStoreFactory 
{
	CPropertyStoreFactory()
		: _Item(NULL)
	{
	}

	DECLARE_NO_REGISTRY()
	DECLARE_NOT_AGGREGATABLE(CPropertyStoreFactory)

	BEGIN_COM_MAP(CPropertyStoreFactory)
		COM_INTERFACE_ENTRY(IPropertyStoreFactory)
	END_COM_MAP()

	IFACEMETHODIMP GetPropertyStore(__in     GETPROPERTYSTOREFLAGS,
									__in_opt IUnknown *,
									__in     REFIID,
									__deref_out_opt VOID * *);
	
	IFACEMETHODIMP GetPropertyStoreForKeys(__in_ecount_opt(Count) CONST PROPERTYKEY *,
		                                   __in      UINT Count,
		                                   __in      GETPROPERTYSTOREFLAGS,
										   __in      REFIID,
										   __deref_out_opt VOID * *);

	STDMETHODIMP GetPropertyStoreToCache(__in REFIID,
										 __deref_out_opt VOID * * );

	STDMETHODIMP Initialize(__in CSevenZipFolder *, __in SevenZip::CSevenZipArchiveItem *);

	static BOOL IsCached(REFPROPERTYKEY);

private:

	HRESULT GetItemName(CComPropVariant &) CONST;
	HRESULT GetItemTypeText(CComPropVariant &) CONST;

	struct PROP_INFO
	{
		PROPERTYKEY Property;

		PROPID PropID;
		HRESULT (CPropertyStoreFactory::*Handler)(CComPropVariant &) CONST;
	};

	STDMETHODIMP CreatePropertyStore(__in_ecount_opt(Count) CONST PROP_INFO *,
		                             __in  UINT Count,
									 __in  REFIID,
								     __deref_out_opt VOID * *);

private:

	static const PROP_INFO   AllProperties[];
	static const PROPERTYKEY CachedPropertyKeys[];

private:

	CComPtrEx<CSevenZipFolder>       _Owner;
	SevenZip::CSevenZipArchiveItem * _Item;
};